<template>
  <div>
    <el-dialog title="添加开学信息登记" width="1100px" :visible.sync="dialogFormVisible">
      <el-form ref="form" :model="form" label-width="130px">
        <el-row>
          <el-col :span="7">
            <el-form-item label="登记日期" class="item_label">
              <el-date-picker type="date" placeholder="选择日期" v-model="form.date1"  ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="单位">
              <el-select v-model="value" filterable  placeholder="请选择单位" >
                <el-option-group v-for="group in options" :key="group.label" :label="group.label">
                  <el-option v-for="item in group.options" :key="item.value" :label="item.label" :value="item.value">
                  </el-option>
                </el-option-group>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="7">
            <el-form-item label="教职工复工人数">
              <el-input-number v-model="teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-button type="primary" @click="addItem" style="float: right; ">添加</el-button>
          </el-col>
        </el-row>



        <div v-for="(item,index) in edus" :key="index" :index="index" :item="item" class="el-card">
          <el-card class="box-card" style="margin-bottom: 5px;">
            <el-row>
              <el-col :span="7">
                <el-form-item label="年级">
                  <el-select v-model="item.valueClass" placeholder="请选择">
                    <el-option v-for="tm in selection" :key="tm.value" :label="tm.label" :value="tm.value">
                    </el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="巳复学班级数">
                  <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="7">
                <el-form-item label="学生实到数">
                  <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                </el-form-item>
              </el-col>
              <el-col :span="3" v-show="index!=0">
                <el-button  style="float: right; padding: 3px 0" type="text" @click="remveItem(index)">移除</el-button>
              </el-col>
            </el-row>


            <el-collapse v-model="activeNames">
              <el-collapse-item title="学生应到数" name="1">
                <el-row style="margin-bottom: 5px;">
                  <el-col :span="8">
                    <el-form-item label="2019年秋季定案数">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">

                    <el-form-item label="转入">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">

                    <el-form-item label="转出">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">

                    <el-form-item label="事假">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>
                </el-row>
              </el-collapse-item>
              <el-collapse-item title="因病缺课、发热等异常人员追踪诊断情况" name="2">

                <el-row style="margin-bottom: 5px;">
                  <el-col :span="8">
                    <el-form-item label="疑似新冠肺炎人数">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">

                    <el-form-item label="其他传染病人数">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>

                  <el-col :span="8">

                    <el-form-item label="其他疾病人数">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">

                    <el-form-item label="待诊断人数">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">

                    <el-form-item label="居家">
                      <el-input-number v-model="item.teachNum" :min="1" :max="1000" label="请填写人数"></el-input-number>
                    </el-form-item>
                  </el-col>
                </el-row>

              </el-collapse-item>


              <el-collapse-item title="备注" name="3">
                <el-input type="textarea" v-model="form.desc"></el-input>
              </el-collapse-item>
            </el-collapse>


          </el-card>
        </div>



        <el-form-item style="margin-top: 5px;">
          <el-button type="primary" style="float: right; margin-left: 5px; ">保存</el-button>
          <el-button @click="dialogFormVisible=false" style="float: right; ">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  import {
    jsonData
  } from '@api/demo.jsondata.table.1'
  import {
    jsonData2
  } from '@api/demo.jsondata.table.2'
  export default {
    mounted() {
      this.options = jsonData();
      this.classMap = jsonData2();
    },
    data() {
      return {
        dialogFormVisible: false,
        form: {
          name: '',
          region: ''
        },
        options: [],
        valueClass: '',
        value: '',
        classMap: [],
        teachNum: 0,
        edus: [{}],
        computedLenth: 0,
        activeNames: ['1', '2']
      }
    },
    computed: {
      selection: function() {
        let map = this.classMap;

        let value_ = this.value;
        this.valueClass = '';
        let res_ = [];
        this.options.forEach(function(v, i) {

          v.options.forEach(function(k, j) {
            if (k.value == value_) {
              res_ = map[v.label];
            }
          })
        })
        this.computedLenth = res_.length
        console.log(this.computedLenth)
        return res_;
      }
    },
    methods: {
      formVisible() {
        this.dialogFormVisible = true
      },
      remveItem(i) {
        if (i !== 0) {
          this.edus.splice(i, 1)
        }
      },
      addItem() {

        if (this.edus.length < this.computedLenth)
          this.edus.push({})
      }
    }

  }
</script>
<style lang="scss">
  @import '~@/assets/recored/public-class.scss';
</style>
